<%@ page language="java" pageEncoding="UTF-8"
	import="com.ivo.model.hr.*"
%>
<%@ include file="/pages/common/taglibs.jsp" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

	String mastIns_id = request.getParameter("mast_id");
	String tmpl_id = request.getParameter("tmpl_id");
	
	Employee user = (Employee)(session.getAttribute("LOGIN_USER"));
	String userId = "";
	if( user != null ) userId = user.getId();
%>

<jsp:useBean id="JSONRPCBridge" scope="session" class="org.jabsorb.JSONRPCBridge" />
<jsp:useBean id="jabsorbService" scope="session" class="com.ivo.jabsorb.JabsorbService" />

<%
	JSONRPCBridge.registerObject("jabsorbService", jabsorbService);
%>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Auto Create Page</title>
    <%@ include file="/pages/common/meta.jsp" %>
	<!-- import EXTJS -->
	<%@ include file="/pages/common/extjs.jsp" %>
	<link rel="stylesheet" type="text/css" href="${ctx }/ext-3.2/ux/fileuploadfield/css/fileuploadfield.css"/>
	<script type="text/javascript" src="${ctx }/ext-3.2/ux/fileuploadfield/FileUploadField.js"></script>
	<script type="text/javascript" src="${ctx }/ext-3.2/ux/SearchField.js"></script>
	
	<script type="text/javascript" src="${ctx }/pages/pdm/DocumentMultiSelectionWindow.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/DccLinkGrid.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/AttachmentGrid.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/FurSelectionWindow.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/BomReport.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/GpReport.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/MaReport.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/FurDetails.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/WorkFlowLog.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/AutoCreate.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/Log.js"></script>
	
	<!-- import JSONRPC -->
	<script type="text/javascript" src="${ctx }/scripts/jsonrpc.js"></script>
	
	<!-- import jQuery -->
	<link type="text/css" href="${ctx }/jQuery/themes/redmond/jquery-ui-1.8.1.redmond.css" rel="stylesheet" />
	<script type="text/javascript" src="${ctx }/jQuery/jquery-1.4.2.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ui.core.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ui.widget.js"></script>

	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ui.tabs.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ui.button.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ui.datepicker.js"></script>
	
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.center.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.numeric.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.numberformatter-1.1.2.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.form-2.43.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ux.formvalidate.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.tablesorter.js"></script>
	
	<link rel="stylesheet" href="${ctx }/jQuery/css/table/blue/style.css" type="text/css" id="" media="print, projection, screen" /> 
	<link type="text/css" href="${ctx }/jQuery/demos.css" rel="stylesheet" />
	<link type="text/css" href="${ctx }/styles/pdm/tool_icon.css" rel="stylesheet" />
	
	<!-- import jquery easy UI-->
	<link rel="stylesheet" type="text/css" href="${ctx }/jQuery/easyui/themes/default/linkbutton.css">
	<link rel="stylesheet" type="text/css" href="${ctx }/jQuery/easyui/themes/icon.css">

	<style type="text/css">
		.warning{
			border:1px  solid red;
		}
		.add {
			background-image: url(<%=request.getContextPath()%>/images/pdm/add.png) !important;
		}
		.delete {
			background-image: url(<%=request.getContextPath()%>/images/pdm/delete.png) !important;
		}
		.cls_validator_error {
			border: 1px solid #F20101;
			background: #FFF39C;
		}
		fieldset {
			font-weight: bold;
			font-family: "Arial";
			font-size: 24;
		}
		.css_number_align {
			text-align: right;
		}
		.jquery-ux-input-dirty {
			background-image: url(<%=request.getContextPath()%>/images/jQuery/dirty.gif);
			background-repeat: no-repeat;  
			background-position: left top;
		}
		.texthidden {
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}
	</style>
	<!-- import css for tag -->
	<style type="text/css">
		.css_singleLine_tag{
			height: 28px;
			width: 89.7%;
			background: #E4F2FB;
			border-bottom: 1px solid #64B8E4;
		}
		.css_singleLine_tag ul{
			list-style: none;
			margin: 2px 10px;
			padding: 0;
			position: absolute;
		}
		.css_singleLine_tag ul li{
			float: left;
			background: #fff;
			line-height: 24px;
			display: block;
			cursor: pointer;
			width: auto;
			text-align: center;
			padding: 0em 1em;
			color: #E17009;
			font-weight: bold;
			border-top: 1px solid #64B8E4;
			border-left: 1px solid #64B8E4;
			border-right: 1px solid #64B8E4;
			border-bottom: 1px solid #64B8E4;
		}
	</style>
	
	<script type="text/javascript">
		var mast_id = '<%=mastIns_id%>';
		var tmpl_fk = '<%=tmpl_id%>';
		window.basePath = '<%=basePath%>';
	
		$(function(){
			$("#basic_tabs").tabs();
			$("#conclusion_tabs").tabs();
			$("#evaluation_tabs").tabs();
			$("#dcc_link_tabs").tabs();
			$("#attachment_tabs").tabs();
			$("#logs_tabs").tabs();
			
			$.ajax({
				type: "post",
				cache: "false",
				url: "/pdm/page/getBasicValues.htm?mast_id="+mast_id,
				dataType: "json",
				contentType: "application/json; charset=utf-8",
				timeout: 20000,
				error: function(){
				    Ext.Msg.alert("Warning:","Basic form loading failed.");
				},
				success: function(json){
				    $("#projectName").attr("value",json[0].projectName);
				    $("#deriveName").attr("value",json[0].deriveName);
				    $("#stage").attr("value",json[0].stage);
				    $("#dateOrder").attr("value",json[0].dateOrder);
				    $("#creator").attr("value",json[0].creator);
				    $("#creatorDept").attr("value",json[0].creatorDept);
				    
				   	$("#"+json[0].conclusion).attr("checked",true);
				   	/*
					 *  渲染Radio Group为button组形式
					 */
					//$("#conclusion").buttonset();
				   	
				    $("#reason").attr("value",renderString(json[0].reason));
				    $("#_collectDocument").attr("value",json[0].documents);
				    
				    $("#fileName").empty();
				    $("#fileName").append("<fieldset>"+json[0].fileName+"</fieldset>");
				    
				    document.title = json[0].fileName;
				}
			});
			
			$.ajax({
				type: "post",
				cache: "false",
				url: "/pdm/page/autocreate.htm?tmpl_fk="+tmpl_fk+"&mast_fk="+mast_id,
				dataType: "json",
				contentType: "application/json; charset=utf-8",
				timeout: 20000,
				error: function(){
				    $("#evaluation_tab_1").html("<font color=red>请求失败，请重新刷新页面！</font>");
				    $("#preloader").hide();
				},
				success: function(json){
				    $("#evaluation_tab_1").html(json[0].data);
				    $("#preloader").hide();
				    
				    formValidate();
				    
				    var divStyle = json[0].style;
				    var bAuth = json[0].auth;
				    
				    if(divStyle.substr(0,1)==0) $("#conclusion_tabs").hide();
				    if(divStyle.substr(1,1)==0)	$("#dcc_link_tabs").hide();
				    else $("#toolbar a:eq(1)").remove();
				    if(divStyle.substr(2,1)==1)
				    {
				    	$("#conclusion_tabs").show();
				    	$("#conclusion table tr td label").each(function(){
				    		$(this).empty();
				    		if($(this).attr("for")=="available")
				    		{
				    			$(this).append("Pass");
				    		}
				    		else if($(this).attr("for")=="unavailable")
				    		{
				    			$(this).append("Fail");
				    		}
				    		else if($(this).attr("for")=="conditional")
				    		{
				    			$(this).append("Conditional Pass");
				    		}
				    	});
				    }
				    /*
					 *  如果没有权限，则设置按钮无效，所有控件只读
					 */
				    if(bAuth != "true")
				    {
				    	/* 变更工具条 */
				    	$("#toolbar a:first-child").remove();
				    	if(divStyle.substr(1,1) == 0) $("#toolbar a:first-child").remove();
				    	/* 使附件无效 */
				    	var btn_add_attach = Ext.getCmp("btn_ext_add_attach");
			    		if(btn_add_attach!=null) btn_add_attach.disable();
			    		
			    		var btn_del_attach = Ext.getCmp("btn_ext_del_attach");
			    		if(btn_del_attach!=null) btn_del_attach.disable();
			    		
					    if(divStyle.substr(1,1) != 0)
					    {
					    	var btn_add_doc = Ext.getCmp("btn_ext_add_doc");
					    	if(btn_add_doc!=null) btn_add_doc.disable();
					    	var btn_add_doc_2 = Ext.getCmp("btn_ext_add_doc_2");
					    	if(btn_add_doc_2!=null) btn_add_doc_2.disable();
					    	var btn_del_doc_2 = Ext.getCmp("btn_ext_del_doc_2");
					    	if(btn_del_doc_2!=null) btn_del_doc_2.disable();
					    }
					    
					    $("input").attr("readonly","true");
					    $("textarea").attr("readonly","true");
					    
					    $("#logs_tabs").hide();
				    }
				    /*
					 *  对敏感的双引号进行特殊处理
					 */
				    $("#basic_form :input").each(function(i){
						this.value = renderString(this.value);
					});
					/*
					 *  对表格中第一个栏位进行对齐
					 */
					$("#evaluation_tab_1 table table tr").each(function(i){
						var colSize = $(this).find("td").size();
						if(colSize>1)
						{
							var width_per = 83/(colSize-1);
							var a = $(this).find("td").first();
							if(!a){
								alert("null");
							}else{
								a.attr("style","height:22px; width:17%;");
							}
							
							$(this).find("td:not(:first)").each(function(j){
								$(this).attr("style","width:"+width_per+"%;");
							});
						}
					});
					/*
					 *  获取
					 */
					if(hasReportType("DT024")||hasReportType("DT037"))
					{
						var objectName = $("#btn_furSelection").parent().prev().find("input").attr("id");
						var objectValue = $("#btn_furSelection").parent().prev().find("input").attr("value");
						var win = null;
						createFollowUpButton(win, objectName, objectValue, bAuth, window.basePath);
					}
					else if(hasReportType("DT025"))
					{
						var objectName = $("#div_selected_material_grid").parent().parent().prev().find("input").attr("id");
						var objectValue = $("#div_selected_material_grid").parent().parent().prev().find("input").attr("value");
						//var objectValue = $("#hidden_BoMParam").attr("value");
						createBoMReport("", objectName, objectValue, bAuth, "");
					}
					else if(hasReportType("DT026"))
					{
						var objectName = $("#btn_dc_query").parent().next().find("input").attr("id");
						//var objectValue = $("#div_selected_material_grid").parent().parent().prev().find("input").attr("value");
						//var objectValue = $("#hidden_BoMParam").attr("value");
						createDcReport("", objectName, "", bAuth, "");
					}
					else if(hasReportType("DT027"))
					{
						var objectName = $("#div_gp_param_grid").parent().parent().prev().find("input").attr("id");
						var objectValue = $("#div_gp_param_grid").parent().parent().prev().find("input").attr("value");
						
						createGpReport("", objectName, objectValue, bAuth, "");
					}
					else if(hasReportType("DT028"))
					{
						var objectName = $("#btn_select_fur").parent().prev().find("input").attr("id");
						var objectValue = $("#btn_select_fur").parent().prev().find("input").attr("value");
						
						var win = null;
						createFurDelay(win, objectName, objectValue, bAuth, "");
					}
					else if(hasReportType("DT036"))
					{
						var objectName = $("#div_ma_param_grid").parent().parent().prev().find("input").attr("id");
						var objectValue = $("#div_ma_param_grid").parent().parent().prev().find("input").attr("value");
						
						createMaReport("", objectName, objectValue, bAuth, "");
					}
					//alert($("#div_selected_material_grid").parent().parent().prev().find("input").attr("value"));
				}
			});	
			/*
			 *  设置toolbar置顶居中;
			 */
			$(window).scroll(function(){
				$('#toolbar').css({top: $(document).scrollTop()});
			});
			
			$(window).resize(function(){
				//$('#toolbar').css({width: "92%"});
			});
			
			$("#toolbar").center({
				vertical: false
			});
			
		});
	</script>
	<script type="text/javascript">
	/********************************************************************************/	
		String.prototype.replaceAll = function(s1,s2){
	    	return this.replace(new RegExp(s1,"g"),s2);   
	  	}
		function renderString(a){
	   		a = a.replaceAll("@39;","\'");
	   		a = a.replaceAll("@34;","\"");
	   		a = a.replaceAll("@13;","\n");
	   		return a;
		}
		function renderGridStr(a){
	   		a = a.replaceAll("@39;","\'");
	   		a = a.replaceAll("@34;","\"");
	   		a = a.replaceAll("@13;","  ");
	   		return a;
		}
	/********************************************************************************/
		function bAuthedReadDccDoc(docNumber,docStatus){
			var cur_usr = '<%=userId%>';
			var jsonrpc = new JSONRpcClient("/pdm/JSON-RPC");
			try{
				var info = jsonrpc.jabsorbService.bAuthedReadDccDoc(docNumber, cur_usr, docStatus);
			}catch(e){
				alert(e);
			}
			return info;
		}
	/********************************************************************************/
		function bDccDocAuth(documentVersion_ID){
			var cur_usr = '<%=userId%>';
			var jsonrpc = new JSONRpcClient("/pdm/JSON-RPC");
			try{
				var info = jsonrpc.jabsorbService.bAuthDccDoc(cur_usr, documentVersion_ID);
			}catch(e){
				alert(e);
			}
			return info;
		}
	/********************************************************************************/
		function hasReportType(data_type){
			var tmpl_id = '<%=tmpl_id%>';
			var jsonrpc = new JSONRpcClient("/pdm/JSON-RPC");
			try{
				var info = jsonrpc.jabsorbService.hasReportType(tmpl_id,data_type);
			}catch(e){
				alert(e);
			}
			return info;
		}
	</script>
	
  </head>
  
  <body>  	
  	<div align="left" class="ui-widget-header ui-corner-all" style="width:92%;z-index:1000;background: #E8E8E8 url(./images/btn/toolbar_background_gray_1.gif) 50% bottom repeat-x;" id="toolbar">
		<a class="easyui-linkbutton l-btn" href="javascript:saveInfo('<%=tmpl_id%>','<%=mastIns_id%>','false')">
			<span class="l-btn-left">
				<span class="l-btn-text icon-save" style="padding-left: 20px;">保存</span>
			</span>
		</a>
		<a class="easyui-linkbutton l-btn" href="javascript:saveInfo('<%=tmpl_id%>','<%=mastIns_id%>','true')">
			<span class="l-btn-left">
				<span class="l-btn-text icon-ok" style="padding-left: 20px;">结案</span>
			</span>
		</a>
		<a class="easyui-linkbutton l-btn" href="javascript:window.close()">
			<span class="l-btn-left">
				<span class="l-btn-text icon-cancel" style="padding-left: 20px;">关闭</span>
			</span>
		</a>
		<!-- 
		<a class="easyui-linkbutton l-btn" href="javascript:window.location.href('ProductDevelopmentManagement.jsp')">
			<span class="l-btn-left">
				<span class="l-btn-text icon-back" style="padding-left: 20px;">Back</span>
			</span>
		</a>
		<a class="easyui-linkbutton l-btn" href="#">
			<span class="l-btn-left">
				<span class="l-btn-text icon-help" style="padding-left: 20px;">Help</span>
			</span>
		</a>
		 -->
		<a class="easyui-linkbutton l-btn" href="javascript:window.location.reload(true)">
			<span class="l-btn-left">
				<span class="l-btn-text icon-reload" style="padding-left: 20px;">刷新</span>
			</span>
		</a>
	</div>
  	<div id="base" align="center">
		<div align="center" style="width:680px; height:26px;"></div>
		
		<div id="fileName" align="center" style="width:92%; margin-top:3px;"><fieldset><font size="6"></font></fieldset></div>
		
		<div id="basic_tabs" style="width:92%; margin-top:3px;">
			<ul>
				<li><a href="#basic_tab_1">基本资料</a></li>
			</ul>
			<div id="basic_tab_1">
				<form id="basic_form1" name="basic_form1" action="">
					<table width="96%;">
					<tr>
						<td style="width:15%;"></td>
						<td style="width:29%;"></td>
						<td style="width:5%;"></td>
						<td style="width:15%;"></td>
						<td style="width:36%;"></td>
					</tr>
					<tr>
						<td align="right">
							<label for="projectName">专案名称:</label>
						</td>
						<td align="left">
							<input type="text" name="projectName" id="projectName" value="" readonly style="width:88%" class="text ui-widget-content ui-corner-all" />
						</td>
						<td></td>
						<td align="right">
							<label for="deriveName">专案版本:</label>
						</td>
						<td align="left">
							<input type="text" name="deriveName" id="deriveName" value="" readonly style="width:70.8%" class="text ui-widget-content ui-corner-all" />
						</td>
					</tr>
					<tr>
						<td align="right">
							<label for="stage">阶段:</label>
						</td>
						<td align="left">
							<input type="text" name="stage" id="stage" value="" readonly style="width:88%" class="text ui-widget-content ui-corner-all" />
						</td>
						<td></td>
						<td align="right">
							<label for="dateCreate">申请日期:</label>
						</td>
						<td align="left">
							<input type="text" name="dateOrder" id="dateOrder" readonly style="width:70.8%" class="text ui-widget-content ui-corner-all" />
						</td>
					</tr>
					<tr>
						<td align="right">
							<label for="creator">申请人员:</label>
						</td>
						<td align="left">
							<input type="text" name="creator" id="creator" value="" readonly style="width:88%" class="text ui-widget-content ui-corner-all" />
						</td>
						<td></td>
						<td align="right">
							<label for="creatorDept">部门名称:</label>
						</td>
						<td align="left">
							<input type="text" name="creatorDept" id="creatorDept" value="" readonly style="width:70.8%" class="text ui-widget-content ui-corner-all" />
						</td>
					</tr>
					</table>
				</form>
			</div>
		</div>
		<div id="evaluation_tabs" style="width:92%">
			<ul>
				<li><a href="#evaluation_tab_1">重要信息</a></li>
			</ul>
			<div id="evaluation_tab_1">
				<div id="preloader"><img src="<%=request.getContextPath()%>/images/pdm/preloading.gif" /></div>
			</div>
		</div>
		<div id="conclusion_tabs" style="width:92%">
			<ul>
				<li><a href="#conclusion_tab_1">结论(NA)</a></li>
			</ul>
			<div id="conclusion_tab_1">
				<div id="conclusion" align="left">
					<table style="width:95%">
						<tr>
							<td style="width:50px;"><input type="radio" id="available" name="conclusion" value="available" /><label for="available">可行</label></td>
							<td style="width:63px;"><input type="radio" id="unavailable" name="conclusion" value="unavailable" /><label for="unavailable">不可行</label></td>
							<td style="width:110px;"><input type="radio" id="conditional" name="conclusion" value="conditional" /><label for="conditional">有条件的</label></td>
							<td>&nbsp;&nbsp;<input type="text" id="reason" name="reason" style="width:85%;" validator="type:string;maxLength:500;" /></td>
						</tr>
					</table>
				</div>
			</div>
		</div>
		<div id="dcc_link_tabs" style="width:92%">
			<ul>
				<li><a href="#dcc_link_tab_1">DCC Link</a></li>
			</ul>
			<div id="dcc_link_tab_1" align=left>
			</div>
		</div>
		<div id="attachment_tabs" style="width:92%">
			<ul>
				<li><a href="#attachment_tab_1">Attachment Link</a></li>
			</ul>
			<div id="attachment_tab_1" align=left></div>
		</div>
		<div id="logs_tabs" style="width:92%">
			<ul>
				<li><a href="#logs_tab_1">修改日志</a></li>
			</ul>
			<div id="logs_tab_1" align=left></div>
		</div>
	</div>
	<div id="hidden_values">
		<input type="hidden" id="_collectDocument" name="_collectDocument" value="" />
		<input type="hidden" id="mast_id" name="mast_id" value="<%= mastIns_id %>" />
		<input type="hidden" id="tmpl_id" name="tmpl_id" value="<%= tmpl_id %>" />
		<input type="hidden" id="login_user" name="login_user" value="<%= userId %>" />
	</div>

  </body>
</html>
